package cn.itsy.dao.user;

import cn.itsy.pojo.EmpAndUserAndRole;
import cn.itsy.pojo.User;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description:
 * @author: MisterGay
 * @date: 2019-06-03 17:03
 */
@Repository(value = "userDaoimpl")
public class UserDaoimpl implements UserDao {
    @Resource(name = "jdbcTemplate")
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<User> queryUserAll(String sql) {
        List<User> query = this.jdbcTemplate.query(sql, new BeanPropertyRowMapper<User>(User.class));
        return query;
    }

    @Override
    public List<EmpAndUserAndRole> queryEmpAndUserAndRole(String sql) {
        List<EmpAndUserAndRole> query = this.jdbcTemplate.query(sql, new BeanPropertyRowMapper<EmpAndUserAndRole>(EmpAndUserAndRole.class));
        return query;
    }

    @Override
    public void saveUser(String sql, User user) {
        this.jdbcTemplate.update(sql, user.getId(), user.getUname(), user.getPass(),
                user.getIsStatus(), user.getRemark(), user.getEmpId());
    }

    @Override
    public List<User> queryUserLastId(String sql) {
        List<User> query = this.jdbcTemplate.query(sql, new BeanPropertyRowMapper<User>(User.class));
        return query;
    }

    @Override
    public void updatUserByuName(String sql, String uname, String oldUname) {
        int update = this.jdbcTemplate.update(sql, uname, oldUname);
    }

    @Override
    public List<User> queryUserByuName(String sql, String uname) {
        return this.jdbcTemplate.query(sql, new BeanPropertyRowMapper<User>(User.class), uname);
    }

    @Override
    public void deleteUserByuName(String sql, String uname) {
        this.jdbcTemplate.update(sql, uname);
    }
}
